package eu.telecombretagne.rsm.gui.frames.panels;

import java.awt.GridLayout;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;

import eu.telecombretagne.rsm.gui.NameConsts;

public class ControlButtonsPanel extends JPanel {
	
	private static final long serialVersionUID = 3239593447255996825L;
	
	private JButton btnStartNetwork;
	private JButton btnStartTransmission;
	
	/**
	 * The constructor of the ControlButtonsPanel.
	 * @param pActionListener A listener for this panel.
	 */
	public ControlButtonsPanel(ActionListener pActionListener){
		setLayout(new GridLayout(1, 3));
		
		//start network button
		btnStartNetwork = createButton(NameConsts.INITIALIZENETWORK, "btnStartNetwork", pActionListener, true);
		add(btnStartNetwork);
		
		//start transmission button
		btnStartTransmission = createButton(NameConsts.STARTTRANSMISSION, "btnStartTransmission", pActionListener, true);
		btnStartTransmission.setEnabled(false);
		add(btnStartTransmission);
	}
	
	private JButton createButton(String pTitle, String pActionCommand, ActionListener pActionListener, Boolean pEnabled){
		JButton button = new JButton(pTitle);
		
		button.setActionCommand(pActionCommand);
		button.setEnabled(pEnabled);
		button.addActionListener(pActionListener);
		
		return button;
	}
	
	/**
	 * Sets start network button enabled.
	 * @param pEnabled If set to <i>true</i> the button is going to be enabled.
	 */
	public void setButtonStartNetworkEnabled(Boolean pEnabled){
		btnStartNetwork.setEnabled(pEnabled);
	}
	
	/**
	 * Sets start transmission button enabled.
	 * @param pEnabled If set to <i>true</i> the button is going to be enabled.
	 */
	public void setButtonStartTransmissionEnabled(Boolean pEnabled){
		setButtonTextAndCommand(btnStartTransmission, NameConsts.STARTTRANSMISSION, "btnStartTransmission");
		btnStartTransmission.setEnabled(pEnabled);
	}
	
	/**
	 * Sets stop transmission button enabled.
	 * @param pEnabled If set to <i>true</i> the button is going to be enabled.
	 */
	public void setButtonStopTransmissionEnabled(Boolean pEnabled){
		setButtonTextAndCommand(btnStartTransmission, NameConsts.STOPTRANSMISSION, "btnStopTransmission");
		btnStartTransmission.setEnabled(pEnabled);
	}
	
	private void setButtonTextAndCommand(JButton pButton, String pText, String pCommand){
		pButton.setActionCommand(pCommand);
		pButton.setText(pText);
	}
}